package components.util
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    
    import mx.resources.ResourceBundle;
    
    public class MessageResource extends EventDispatcher
    {
		public static const PT_BR:String = "pt_BR";
		public static const EN_US:String = "en_US";
		public static const ES_ES:String = "es_ES";
		
		public function MessageResource(singletonEnforcer:SingletonEnforcer)
		{			
		}
		
    	private static var messageResource:MessageResource;
      
      	[ResourceBundle("messageResource_pt_BR")]
	  	private var resourceBundlePtBR:ResourceBundle;
		
	  	private var currentLanguage:String;

        public static function getInstance():MessageResource
        {
		    if( messageResource == null )
		    {
		 		messageResource = new MessageResource(new SingletonEnforcer());
		 		messageResource.setLanguage(MessageResource.PT_BR);
		    }
			return messageResource;
        }
        
        public function setLanguage(language:String):void
        {
        	this.currentLanguage = language;
			var e:Event = new Event("langChange");
			this.dispatchEvent(e);  	
        }

		[Bindable(event="langChange")]
        public function getText(key:String):String 
        {
        	var text:String = "";
        	
            if(currentLanguage == PT_BR)
            {
            	text = resourceBundlePtBR.content[key];
            }
            
            return text;
        }

    }
}

class SingletonEnforcer{};